package com.np.moneylover;

import java.util.List;


import com.np.adapter.ThuChiAdapter;
import com.np.dao.CheckLoginData;
import com.np.dao.SoThuChiData;
import com.np.dao.ThuChiDataListener;
import com.np.dto.ThuChi;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class SoChiTieu extends Activity implements ThuChiDataListener{
	List<ThuChi> lstthu=null;
	ListView lv=null;
	ProgressDialog dialog=null;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
    	// TODO Auto-generated method stub
    	super.onCreate(savedInstanceState);
    	
    	this.setContentView(R.layout.sochitieu);
    	lv=(ListView)findViewById(R.id.listthuchi);
    	LoadData();
    }

	private void LoadData() {
		//ProgressDialog.show(this, "", "Kiểm tra đăng nhập ...");
        //chay localhost thi la 10.0.2.2
    	String username="wjnter";
        String url = "http://10.0.2.2:8080/connect_android/getthuchi.php?username="+username+"&magd="+"1";
        SoThuChiData task = new SoThuChiData(this);
        task.execute(url);
		
	}

	@Override
	public void onGetListThuChiComplete(List<ThuChi> data) {
		// TODO Auto-generated method stub
		
		if (dialog != null)
			dialog.dismiss();

		// Luu vao mang Arraylist de su ly
		lstthu = data;

		// Hien thi len list

		ThuChiAdapter adapter = new ThuChiAdapter(
				SoChiTieu.this, R.layout.layoutsochitieuadapter, data);
		// set the adapter to list

	    lv.setAdapter(adapter);

		/*lv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub

				int check = lstban.get(arg2).getTinhtrang();
				if (check == 1) {
					cktinhtrang.setChecked(true);
				}
				txtten.setText(lstban.get(arg2).getTenban().toString());
				
				int tinhtrang = lstban.get(arg2).getTinhtrang();
				if (tinhtrang == 1)
					cktinhtrang.setChecked(true);
				else
					cktinhtrang.setChecked(false);
				dataClick = lstban.get(arg2);

			}
		});*/

		
	}

	@Override
	public void onGetListThuChiFailure(String msg) {
		// TODO Auto-generated method stub
		Toast.makeText(this,"thatbai" ,Toast.LENGTH_SHORT).show();

	}
}
